package com.aier.admin.action;

import java.sql.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.eicp.ghostboy.futil.MD5Util;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.service.IAdminUserService;
import com.aier.common.dao.ICommonDAO;
import com.aier.proxy.service.IProxyService;
import com.aier.user.common.UserFinalPageSize;
import com.aier.user.entity.User;

@Scope("prototype")
@Component("adminUserAction")
public class AdminUserAction extends AdminBaseAction {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    @Resource(name = "adminUserService")
    private IAdminUserService adminUserService;
    
    //页数
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    //错误码
    private int s;
    
    // 排序方式
    private String sord;
    // 排序字段
    private String sort;
    
    private Long uid;
    // 管理员密码
    private String password;
    
    // 管理员列表
    private List<User> userList;
    
    // 管理员帐号
    private String account;
    // 管理员姓名
    private String realname;
    // 管理员昵称
    private String nikename;
    // 管理员性别
    private Short sex;
    // 管理员生日
    private Date birthday;
    
    @Override
    public String execute(){
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String searchUser() {
        if (page <= 0) {
            page = 1;
        }
        int sortable=-1;
        if("uid".equals(sort)){
            sortable = ("asc".equals(sord))?IProxyService.ENTRANCE_SORTABLE_SN:IProxyService.ENTRANCE_SORTABLE_SN_DESC;
        }
        Map<String, Object> map = null;
        map = adminUserService.searchAdminUserList(page, UserFinalPageSize.USERIC_ICARD_PAGESIZE, sortable);
        userList = (List<User>)map.get(ICommonDAO.OBJ_LIST);
        if (null == userList) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }
    // 修改密码
    public String modifyPwd() {
        s = adminUserService.updatePwd(uid, MD5Util.getMD5(password));
        return SUCCESS;
    }
    // 创建管理员
    public String createUser() {
        
        s = adminUserService.insertUser(account, MD5Util.getMD5(password), realname, nikename, sex, birthday);
        return SUCCESS;
    }
    
    public int getPage() {
        return page;
    }


    public void setPage(int page) {
        this.page = page;
    }


    public int getPage_size() {
        return page_size;
    }


    public int getPage_count() {
        return page_count;
    }


    public int getCount() {
        return count;
    }


    public int getS() {
        return s;
    }

    public void setSord(String sord) {
        this.sord = sord;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public void setAdminUserService(IAdminUserService adminUserService) {
        this.adminUserService = adminUserService;
    }

    public List<User> getUserList() {
        return userList;
    }

    public void setUserList(List<User> userList) {
        this.userList = userList;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getNikename() {
        return nikename;
    }

    public void setNikename(String nikename) {
        this.nikename = nikename;
    }

    public Short getSex() {
        return sex;
    }

    public void setSex(Short sex) {
        this.sex = sex;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    
}
